/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.bo;

import org.ipti.br.tag.dao.FunctionalityFacade;
import org.ipti.br.tag.entity.Functionality;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import javax.ejb.Stateless;

/**
 *
 * @author israel
 */
@Stateless
public class FunctionalityBO {

    @Inject
    private FunctionalityFacade functionalityDAO;

    public FunctionalityFacade getFunctionalityDAO() {
        return functionalityDAO;
    }

    public void create(Functionality functionality) {
        getFunctionalityDAO().create(functionality);
    }

    public void edit(Functionality functionality) {
        getFunctionalityDAO().edit(functionality);
    }

    public void remove(Functionality functionality) {
        getFunctionalityDAO().remove(functionality);
    }

    public Functionality find(Object id) {
        return getFunctionalityDAO().find(id);
    }

    public List<Functionality> findAll() {
        return getFunctionalityDAO().findAll();
    }

    public void editForSynchronization(Functionality functionality) {
        getFunctionalityDAO().editForSynchronization(functionality);
    }

    public List<Functionality> getFunctionalityChildren(Long functionalityID) {
        return getFunctionalityDAO().getFunctionalityChildren(functionalityID);
    }

    public List<Functionality> getLeafChildren(Long functionalityID) {
        List<Functionality> listAux = new ArrayList<Functionality>();
        for (Functionality functionality : getFunctionalityChildren(functionalityID)) {
            if (getLeafChildren(functionality.getId()).isEmpty()) {
                listAux.add(functionality);
            } else {
                listAux.addAll(getLeafChildren(functionality.getId()));
            }
        }
        return listAux;
    }
}
